package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class CollectionOperator {
    public List<Integer> getListByInterval(int left, int right) {
        List<Integer> list = new ArrayList<>();
        if(left>right){
            for (;left>=right;left--){
                list.add(left);
            }
        }else if (left<right){
            for (;left<=right;left++){
                list.add(left);
            }
        }

        return list;
    }

    public List<Integer> getEvenListByIntervals(int left, int right) {
        List<Integer> list = new ArrayList<>();
        if(left>right){
            for (;left>=right;left--){
                if(left%2==0){
                    list.add(left);
                }
            }
        }else if (left<right){
            for (;left<=right;left++){
                if(left%2==0) {
                    list.add(left);
                }
            }
        }

        return list;
    }

    public List<Integer> popEvenElments(int[] array) {
        List<Integer> list = new ArrayList<>();
        for ( Integer arr:array) {
            if (arr%2==0){
                list.add(arr);
            }
        }
        Set<Integer> middleHashSet = new HashSet<Integer>(list);

        List<Integer> afterHashSetList = new ArrayList<Integer>(middleHashSet);
        return  afterHashSetList;
    }

    public int popLastElment(int[] array) {
        return array[array.length-1];
    }

    public List<Integer> popCommonElement(int[] firstArray, int[] secondArray) {
        List<Integer> list = new ArrayList<>();
        for ( int first:firstArray) {
            for (int second:secondArray) {
                if (first==second){
                    list.add(first);
                }
            }
        }
        return list;
    }

    public List<Integer> addUncommonElement(Integer[] firstArray, Integer[] secondArray) {
        List<Integer> list = new ArrayList<>();
        boolean b = false;
        for (int first:firstArray) {
            list.add(first);
        }
        for (Integer seond:secondArray) {

            for (Integer first:firstArray) {
                if(first==seond){
                    b=true;
                }
            }
            if(b==false){
                list.add(seond);

            }
            b=false;
        }
        for (Integer l:list) {
            System.out.print(l+" ");
        }
        return list;
    }


}
